import numpy as np

x = np.array([1, 2, 3])
y = np.array([4, 5, 6])

# concatenate矩阵合并
z = np.concatenate([x, y])
print(z)
X = z.reshape(2, -1)
print(X)
print(np.concatenate([X, X]))   # 默认为0轴
print(np.concatenate([X, X], axis=1))

# vstack()沿竖直方向堆叠合并矩阵,与加了轴参数的concatenate等价
print(np.vstack([X, x]))
# hstack()沿在水平轴方向堆叠矩阵
A = np.full((2, 4), 100)
print(np.hstack([X, A]))

# 分割操作
x = np.arange(10)
# 将x切分为3份,必须传入数组作为分割点
x1,x2,x3 = np.split(x, [3, 7])
print(x1, x2, x3)
x4, x5 = np.split(x, [5])
print(x4, x5)
A = np.arange(16).reshape((4, 4))
# 沿竖直方向分割矩阵
A1, A2 = np.split(A, [3], axis=1)
print("A1:", A1)
print("A2:", A2)

# vsplit()沿竖直方向分割矩阵
upper, lower = np.vsplit(A, [1])
print("UPPER:", upper)
print("LOWER:", lower)
# hsplit()沿水平方向分割矩阵
left, right = np.hsplit(A, [3])
print("LEFT:", left)
print("Right:", right)

# 分割的应用场景：
data = np.arange(16).reshape((4,4))
x, y = np.hsplit(data, [-1])
print("dat:", x)
# 将矩阵转为向量
print("label:", y[:, 0])